package com.whut.mobilesafe.activity;

import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.whut.mobilesafe.R;
import com.whut.mobilesafe.service.BlackListService;
import com.whut.mobilesafe.utils.PrefUtils;
import com.whut.mobilesafe.utils.ServiceUtils;
import com.whut.mobilesafe.view.SettingItemView;

/**
 * 作    者:yubo.xiaoyubo
 * 时    间：2015/12/22 20:18
 * 版    本：1.0
 * 描    述：设置页面
 */
public class SettingActivity extends Activity {

    private SettingItemView sivAutoUpdate;
    private SettingItemView sivBlackList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        sivAutoUpdate = (SettingItemView) findViewById(R.id.siv_auto_update);
        sivBlackList = (SettingItemView) findViewById(R.id.siv_black_list);

        boolean autoUpdate = PrefUtils.getBoolean("auto_update", true, getApplicationContext());
        sivAutoUpdate.setChecked(autoUpdate);

        sivAutoUpdate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean ischecked = sivAutoUpdate.isChecked();
                if (ischecked) {
                    sivAutoUpdate.setChecked(false);
                    PrefUtils.putBoolean("auto_update", false, getApplicationContext());
                } else {
                    sivAutoUpdate.setChecked(true);
                    PrefUtils.putBoolean("auto_update", true, getApplicationContext());
                }
            }
        });

        boolean blackService = ServiceUtils.isServiceRunning(this, "com.whut.mobilesafe.service.BlackListService");
        sivBlackList.setChecked(blackService);
        sivBlackList.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean ischecked = sivBlackList.isChecked();
                Intent service = new Intent(getApplicationContext(), BlackListService.class);
                if (ischecked) {
                    sivBlackList.setChecked(false);
                    stopService(service);
                } else {
                    sivBlackList.setChecked(true);
                    startService(service);
                }
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
